from typing import Optional, Any
from datetime import datetime
from pydantic import BaseModel, ConfigDict


class BaseSchema(BaseModel):
    """基础Schema"""
    model_config = ConfigDict(from_attributes=True)


class PaginationParams(BaseModel):
    """分页参数"""
    page: int = 1
    page_size: int = 20

    model_config = ConfigDict(
        json_schema_extra={
            "example": {
                "page": 1,
                "page_size": 20
            }
        }
    )


class PaginationResponse(BaseModel):
    """分页响应"""
    total: int
    page: int
    page_size: int
    pages: int
    items: list[Any]


class ResponseModel(BaseModel):
    """统一响应模型"""
    code: int = 200
    message: str = "Success"
    data: Optional[Any] = None


class TimestampMixin(BaseModel):
    """时间戳混合类"""
    create_time: Optional[datetime] = None
    update_time: Optional[datetime] = None


class TenantMixin(BaseModel):
    """多租户混合类 - 匹配RuoYi结构"""
    tenant_id: str = '000000'


# Plus-UI 兼容的基础类型 - 匹配RuoYi字段命名
class BaseEntity(BaseModel):
    """基础实体 - 匹配RuoYi字段结构"""
    createDept: Optional[int] = None  # 创建部门
    createBy: Optional[int] = None    # 创建者
    createTime: Optional[str] = None  # 创建时间
    updateBy: Optional[int] = None    # 更新者
    updateTime: Optional[str] = None  # 更新时间
    remark: Optional[str] = None      # 备注


class PageQuery(BaseModel):
    """分页查询 - Plus-UI兼容"""
    pageNum: Optional[int] = 1
    pageSize: Optional[int] = 10
    orderBy: Optional[str] = None
    isAsc: Optional[str] = None  # 排序方向


class StatusMixin(BaseModel):
    """状态混合类 - RuoYi通用状态字段"""
    status: Optional[str] = '0'  # 0正常 1停用


class SoftDeleteMixin(BaseModel):
    """软删除混合类 - RuoYi软删除字段"""
    delFlag: Optional[str] = '0'  # 0存在 1删除